package cn.lxb.web.starter.template.autoconfigure;

import cn.lxb.web.starter.template.autoconfigure.properties.SequenceProperties;
import cn.lxb.web.starter.template.sequence.Sequence;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * 分布式序列自动配置
 *
 * @author 54lxb
 * @since 2019-11-20
 */
@Configuration
@EnableConfigurationProperties(SequenceProperties.class)
public class SequenceAutoconfigure {

    /**
     * 分布式序列自动配置
     *
     * @param properties 分布式序列自动配置属性
     * @return 分布式序列
     */
    @Bean
    public Sequence sequence(SequenceProperties properties) {
        return new Sequence(properties.getWorkerId(), properties.getDataCenterId());
    }
}
